package date时间.LocalDate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Date;
import java.util.regex.Pattern;

public class text1 {
    public static void main(String[] args) throws ParseException {
        //设置自定义时间：of
        LocalDate l = LocalDate.of(1949,10,1);
        System.out.println(l);

        SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd");
        Date d0 = s1.parse(String.valueOf(l));

        SimpleDateFormat s2 = new SimpleDateFormat("yyyy年MM月dd日");
        String f1 = s2.format(d0);
        System.out.println(f1);

        System.out.println("----------------");

        //设置当前系统时间： now
        LocalDate l1  = LocalDate.now();
        System.out.println(l1);

        System.out.println("----------------");

        //get：获取时间
        int year = l.getYear();
        int month = l.getMonthValue();
        Month month1 = l.getMonth();//获取英文月期
        int dayOfMonth = l.getDayOfMonth();
        System.out.println(year);
        System.out.println(month);
        System.out.println(month1);
        System.out.println(dayOfMonth);

        System.out.println("----------------");

        //判断时间前后顺序
        System.out.println(l);
        System.out.println(l1);
        System.out.println(l.isAfter(l1));//前者是否在后者之后
        System.out.println(l.isBefore(l1));//前者是否在后者之前

        System.out.println("----------------");

        //判断今天是否是你的生日
        LocalDate d1 = LocalDate.of(2003,8,26);//生日
        LocalDate d2 = LocalDate.now();//当前系统时间
            //获取月日对象：MonthDay
        MonthDay nowDay = MonthDay.now();
        MonthDay birDay = MonthDay.of(d1.getMonthValue(), d1.getDayOfMonth());
        System.out.println(nowDay);
        System.out.println(birDay);
        System.out.println("今天是否是你的生日："+nowDay.equals(birDay));

        System.out.println("----------------");

//        LocalDate d1 = LocalDate.of(2003,8,26);//生日
//        LocalDate d2 = LocalDate.now();//当前系统时间

        //计算时间间隔:Period : 使用于LocalDate，时间为年月日
        Period between = Period.between(d1, d2);//后面的时间减前面一个时间
        System.out.println(between);
            //获取时间间隔的年月日
        int years = between.getYears();
        int months = between.getMonths();
        int days = between.getDays();
        System.out.println(d1);
        System.out.println(d2);
        System.out.println("时间间隔为："+years+"年"+months+"月"+days+"日");

        System.out.println("----------------");

        //计算时间间隔:Duration : 使用于LocalDateTime，时间为年月日时分秒
        LocalDateTime lt1 = LocalDateTime.of(2003,8,26,06,30,20);
        LocalDateTime lt2 = LocalDateTime.now();
        System.out.println(lt1);
        System.out.println(lt2);
            //计算时间间隔
        Duration between1 = Duration.between(lt1, lt2);//计算两者相隔的时分秒
        System.out.println(between1);
            //将两者相差的时间转化为具体的
        long days1 = between1.toDays();
        System.out.println(days1+"天");

        long hours = between1.toHours();
        System.out.println(hours+"时");

        long minutes = between1.toMinutes();
        System.out.println(minutes+"分");

        long millis = between1.toMillis();
        System.out.println(millis+"毫秒");

        long nanos = between1.toNanos();
        System.out.println(nanos+"纳秒");
    }
}
